<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <style>

    </style>
</head>

<body>
    <div id="app">
        <p>{{num | toFixed2}}</p>
        <p>{{now | dateFormate}}</p>
    </div>
    <hr>
    <div id="app1">
        {{num | toFixed2}}
    </div>
</body>
<script>
    //全局过滤器
    Vue.filter('toFixed2', function(val) {
        return val.toFixed(2)
    })

    // 局部过滤器
    var vm = new Vue({
        el: '#app',
        data: {
            num: 100,
            now: Date.now()
        },
        filters: {
            // toFixed2(val) {
            //     return val.toFixed(2)
            // }
            dateFormate(date) {
                var d = new Date(date);
                var year = d.getFullYear();
                var month = d.getMonth() + 1;
                var day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate();
                var hour = d.getHours();
                var minutes = d.getMinutes();
                var seconds = d.getSeconds();
                return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds;
            }
        }
    })

    var vm = new Vue({
        el: '#app1',
        data: {
            num: 101
        }
    })
</script>

</html>